package com.yz.lzq.liwushuo.ui.modules.home.boutique;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.yz.lzq.liwushuo.R;
import com.yz.lzq.liwushuo.ui.modules.comminterface.OnMyItemClickListener;
import com.yz.lzq.liwushuo.jsonbean.home.boutique.HomeBoutiqueFenLeiBean;

import java.util.List;

/**
 * Created by Administrator on 2016/12/14.
 */

public class HomeBoutiqueGridViewAdapter extends BaseAdapter {
    private Context context = null;
    private OnMyItemClickListener listener = null;
    private List<HomeBoutiqueFenLeiBean.DataBean.SecondaryBannersBean> mList = null;


    public HomeBoutiqueGridViewAdapter(Context context, List<HomeBoutiqueFenLeiBean.DataBean.SecondaryBannersBean> _List, OnMyItemClickListener listener) {
        this.context = context;
        this.mList = _List;
        this.listener = listener;
        if (mList.size() >= 6) {
            mList.remove(6);
        }
    }


    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        VieHolder vieHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_headerview_img, null);
            vieHolder = new VieHolder(convertView);
            convertView.setTag(vieHolder);
        } else {
            vieHolder = (VieHolder) convertView.getTag();
        }
        Glide.with(context).load(mList.get(position).getImage_url()).into(vieHolder.imageView_headerView_item);
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.clickMyItem(view, position);
            }
        });
        return convertView;
    }

    public class VieHolder {
        private ImageView imageView_headerView_item;

        public VieHolder(View view) {
            imageView_headerView_item = (ImageView) view.findViewById(R.id.imageView_headerView_item);

        }
    }

    /**
     * 刷新gridView
     */
    public void reLoadGridView(List<HomeBoutiqueFenLeiBean.DataBean.SecondaryBannersBean> _List) {
        mList.clear();
        for (int i = 0; i <6; i++) {
            mList.add(_List.get(i));
        }
    /*    mList.addAll(_List);
        if (mList.size() >= 6) {
            mList.remove(6);
        }*/
        notifyDataSetChanged();
    }
}
